package com.jsaber.blogSystem.controller;

import com.jsaber.blogSystem.pojo.Article;
import com.jsaber.blogSystem.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author zhouzijia
 * @version 1.0
 * @description
 * @date 2020/12/13 11:02
 */

@Controller
public class BolgSystemController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/index")
    public String index(Model model, Integer page){

        Page<Article> all = articleService.articleList(page);

        // 设置返回页面的参数和值
        // list ：文章列表
        // totalPages : 总页数
        // currentPage ： 当前页数
        model.addAttribute("list", all.getContent());
        model.addAttribute("totalPage", all.getTotalPages());
        model.addAttribute("currentPage", page == null? 1 : page);

        // 返回的 html 页面路径
        return "client/index";
    }
}
